# encoding=utf-8
import sys
reload(sys)
sys.setdefaultencoding('utf-8')

class operation():
    def __int__(self, driver):
        self.driver = driver
    # 重写元素定位的方法--通过id定位
    @staticmethod
    def find_element(self, loc):
        try:
            return self.driver.find_element_by_id(loc)
        except Exception as e:
            print("未找到%s" % (loc))

    @staticmethod
    def isElementExsit(self,id):
        '''判断元素id是否在当前页面存在'''
        return id in self.driver.page_source
    @staticmethod
    def getCurrentElementXY(dr,elementStr):
        '''处理popuwindow无法识别的控件，通过XY坐标来操作'''
        views = dr.find_elements_by_class_name(elementStr)
        sizeViews = len(views)
        a = views[sizeViews - 1]
        xForView = a.location_once_scrolled_into_view['x']
        yForView = a.location_once_scrolled_into_view['y']
        xForPhone = dr.get_window_size()['width']
        yForPhone = dr.get_window_size()['height']
        returnValue={
            "xForView":xForView,
            "yForView":yForView,
            "xForPhone":xForPhone,
            "yForPhone":yForPhone
        }
        return  returnValue